﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharePointClient
{
    public enum BeforeOrAfter { Before, After }

    public interface IStateable
    {
         BeforeOrAfter State { get; }
    }
  

    public class GuidEventArgs : EventArgs, IStateable,IDisposable
    {
        private Guid guid;
        BeforeOrAfter state;
        bool cached;
        object obj;
        public GuidEventArgs(Guid guid, BeforeOrAfter state, bool cached,object obj)
        { this.guid = guid; this.state = state; this.cached = cached; this.obj = obj; }
        public Guid Guid { get { return guid; } }
        public bool Cached { get { return cached; } }
        public object SharePointobject { get { return obj; } }
        #region IStateable Member

        public BeforeOrAfter State
        {
            get { return state; }
        }

        #endregion

        #region IDisposable Member

        public void Dispose()
        {
            obj=null;
        }

        #endregion
    }
    public class UriEventArgs : EventArgs, IStateable
    {
        private Uri uri;
        private BeforeOrAfter state;
        public UriEventArgs(Uri uri, BeforeOrAfter state)
        { this.uri = uri; this.state = state; }
        public Uri Uri { get { return uri; } }
        #region IStateable Member

        public BeforeOrAfter State
        {
            get { return state; }
        }

        #endregion
    }
    public class ProgressEventArgs : EventArgs
    {
        private string what;
        private BeforeOrAfter state;
        private Guid guid;
        public ProgressEventArgs(string what, BeforeOrAfter state)
        {
            this.state = state; this.what = what; guid = new Guid();
        }
        public ProgressEventArgs(string what, BeforeOrAfter state,Guid oldGuid)
        {
            this.state = state; this.what = what; guid = oldGuid;
        }
        public string Operation { get { return what; } internal set { what = value; } }
        public Guid Guid { get { return guid; }}
        public BeforeOrAfter State { get { return state; } internal set { state = value; } }
    }
    public class FileoperationEventArgs : EventArgs
    {
        private Guid guid;
        private byte[] buffer;
        private Uri file;
        private bool download;
        private int size;
        private int loaded;

        public FileoperationEventArgs(Uri file, bool isDownload, int size)
        {
            this.file = file;
            this.size = size;
            this.download = isDownload;
            this.loaded = 0;
            this.guid = new Guid();
        }
        public Guid Guid { get { return guid; } }
        public double Percent { get { return Convert.ToDouble(loaded) / Convert.ToDouble(size) * 100.0; } }
        public bool Completed { get { return loaded == size; } }
        public int Loaded { get { return loaded; } internal set { loaded = value; } }
        public Uri File { get { return file; }}
        public int Size { get { return size; }}
        public int Remains { get { return size - loaded; } }
    
    }
    public delegate void GuidEventHandler(object sender, GuidEventArgs e);
    public delegate void UriEventHandler(object sender, UriEventArgs e);
    public delegate void ProgressEventHandler(object sender, ProgressEventArgs e);
    public delegate void FileoperationHandler(object sender, FileoperationEventArgs e);
}
